﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Spring.Data.NHibernate.Generic.Support;

using NHibernate;

using BOSS.Dao.Security;
using BOSS.Domain.Security;

namespace BOSS.Dao.NHibernate.Security
{
    /// <summary>
    /// 特权 DAO
    /// </summary>
    public class PrivilegeDao : HibernateDaoSupport, IPrivilegeDao
    {
        #region IPrivilegeDao 成员

        /// <summary>
        /// 获取所有特权
        /// </summary>
        /// <returns></returns>
        public IList<Privilege> SelectAll()
        {
            IList<string> names = this.HibernateTemplate.ExecuteFind<string>(delegate(ISession session)
            {
                return session.CreateSQLQuery("SELECT DISTINCT PrivilegeName FROM PrivilegeSettings ORDER BY PrivilegeName")
                    .SetCacheable(false)
                    .List<string>();
            });
            return names.Select(n => new Privilege(n, PermissionType.INHERIT)).ToList();
        }

        #endregion
    }
}
